package com.dankegongyu.lib.common.util;

import android.os.Environment;

/**
 * @author WuPuquan
 * @version 1.0
 * @since 2017/11/9 10:30
 */

public class SDCardUtil {

    private SDCardUtil() {
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 检测手机是否有SD卡
     *
     * @return
     */
    public static boolean hasSDCard() {
        String status = Environment.getExternalStorageState();
        return Environment.MEDIA_MOUNTED.equals(status);
    }

    /**
     * 获取SD卡路径，没有SD卡使用内部存储
     *
     * @return 存储路径
     */
    public static String getSDCardPath() {
        if (hasSDCard()) {
            // SD卡路径：/storage/sdcard0
            return Environment.getExternalStorageDirectory().getAbsolutePath();
        } else {
            // 内部存储路径：/data/data/包名
            return Environment.getDataDirectory() + "/data/" + GlobalContext.getApplication().getPackageName();
        }
    }
}
